from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.
class Right(models.Model):
    title = models.CharField(max_length=32, verbose_name='菜单名称',help_text= '菜单名称')
    href = models.CharField(max_length=128, verbose_name='菜单链接', help_text='菜单链接',null=True,blank=True)
    icon = models.CharField(max_length=128,verbose_name='图标',help_text='图标')
    openType = models.CharField(max_length=32, verbose_name='打开方式', help_text='打开方式',null=True,blank=True)
    type = models.CharField(max_length=32,verbose_name='类型',help_text='类型')
    code = models.CharField(max_length=32,verbose_name='权限编码',help_text='权限编码')
    parent_id = models.IntegerField(verbose_name='父级菜单',help_text='父级菜单',null=True,blank=True)
    sort = models.IntegerField(verbose_name='排序',help_text='排序')
    enabled = models.BooleanField(verbose_name='是否启用',help_text='是否启用')
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'right'

class Dept(models.Model):
    name = models.CharField(max_length=32, verbose_name='部门名称',help_text='部门名称')
    code = models.CharField(max_length=32, verbose_name='部门编码',help_text='部门编码')
    parent_id = models.ForeignKey('Dept',on_delete=models.CASCADE, null=True, blank=True,verbose_name='父级部门',help_text='父级部门')
    leader = models.ForeignKey('auth.User',on_delete=models.CASCADE, null=True, blank=True,verbose_name='部门主管',help_text='部门主管')
    sort = models.IntegerField(verbose_name='排序',help_text='排序')
    enabled = models.BooleanField(verbose_name='是否启用',help_text='是否启用')
    remark = models.CharField(max_length=128, verbose_name='备注',help_text='备注',null=True,blank=True)
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'dept'

class Role(models.Model):
    name = models.CharField(max_length=32, verbose_name='角色名称',help_text='角色名称')
    code = models.CharField(max_length=32, verbose_name='角色编码',help_text='角色编码')
    enable = models.BooleanField(verbose_name='是否启用',help_text='是否启用')
    remark = models.CharField(max_length=128, verbose_name='备注',help_text='备注')
    details = models.TextField(verbose_name='角色详情',help_text='角色详情')
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'role'

class RolePower(models.Model):
    role_id = models.ForeignKey('Role',on_delete=models.CASCADE, null=True, blank=True,verbose_name='角色',help_text='角色')
    right_id = models.ForeignKey('Right',on_delete=models.CASCADE, null=True, blank=True,verbose_name='权限',help_text='权限')
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'role_power'

class UserRole(models.Model):
    user_id = models.ForeignKey('auth.User',on_delete=models.CASCADE, null=True, blank=True,verbose_name='用户',help_text='用户')
    role_id = models.ForeignKey('Role',on_delete=models.CASCADE, null=True, blank=True,verbose_name='角色',help_text='角色')
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'user_role'

class UserDept(models.Model):
    user_id = models.ForeignKey('auth.User',on_delete=models.CASCADE, null=True, blank=True,verbose_name='用户',help_text='用户')
    dept_id = models.ForeignKey('Dept',on_delete=models.CASCADE, null=True, blank=True,verbose_name='部门',help_text='部门')
    ca_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间', help_text='创建时间')
    up_time = models.DateTimeField(auto_now=True,verbose_name='更新时间',help_text='更新时间')

    class Meta:
        db_table = 'user_dept'